import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const routes = [
  {
    path: '/login',
    component: () => import('@/views/Login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/Login/register'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/patient'
  },
  {
    path: '/patient',
    name: 'patient',
    component: Layout,
    children: [{
      path: '',
      component: () => import('@/views/patient/index'),
      meta: { title: '医院', icon: 'el-icon-data-board' }
    },{
      path: 'order',
      permission: 'patient:order',
      component: () => import('@/views/patient/order'),
      meta: { title: '医生医嘱' }
    }]
  },
  {
    path: '/doctor',
    name: 'doctor',
    component: Layout,
    children: [{
      path: '',

      component: () => import('@/views/doctor/index'),
      meta: { title: '医生入口', icon: 'el-icon-data-board' }
    }]
  },
  {
    path: '/clerk',
    name: 'clerk',
    component: Layout,
    children: [{
      path: '',

      component: () => import('@/views/clerk/index'),
      meta: { title: '收费员入口', icon: 'el-icon-data-board' }
    }]
  },
  {
    path: '/admin',
    name: 'admin',
    component: Layout,
    permission: 'admin',
    meta: { title: '后台管理', icon: 'el-icon-data-board' },
    children: [{
      path: 'department',
      permission: 'admin:department',
      component: () => import('@/views/admin/department'),
      meta: { title: '住院科室管理' }
    }, {
      path: 'medicine',
      permission: 'admin:medicine',
      component: () => import('@/views/admin/medicine'),
      meta: { title: '药品管理' }
    }]
  },  
  {
    path: '/user',
    name: 'user',
    component: Layout,
    permission: 'user',
    meta: { title: '用户管理', icon: 'el-icon-data-board' },
    children: [{
      path: 'doctor',
      permission: 'user:doctor',
      component: () => import('@/views/user/doctor'),
      meta: { title: '医生' }
    }, {
      path: 'clerk',
      permission: 'user:clerk',
      component: () => import('@/views/user/clerk'),
      meta: { title: '收费员' }
    }]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]




const createRouter = () => new Router({
  // mode: 'history', // require service support
  base: '/SW21-H2-05',
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: routes
})

const router = createRouter()

// 重置路由方法
export function resetRouter() {
  // 得到一个全新的router实例对象
  const newRouter = createRouter()
  // 使用新的路由记录覆盖掉老的路由记录
  router.matcher = newRouter.matcher
}

export default router

